﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Xml;
using System.Xml.XPath;

namespace SBPweb.MediaCenter.Common.Modularity
{
    public class ModulesConfiguration
    {

        #region Protected fields

        protected XPathDocument pXDoc;
        protected XPathNavigator pXNav;
        protected List<FileInfo> pModules = new List<FileInfo>();

        #endregion

        #region Constructor logic

        public ModulesConfiguration(string path)
        {
            pXDoc = new XPathDocument(path);

            Initialize();
        }

        #endregion

        #region Public properties

        public List<FileInfo> Modules
        {
            get
            {
                return pModules;
            }
        }

        #endregion

        #region Public methods

        public void Initialize()
        {
            pXNav = pXDoc.CreateNavigator();
            pXNav.MoveToFirstChild();
            pXNav.MoveToFirstChild();
            XPathNodeIterator xPNI = pXNav.SelectChildren(XPathNodeType.Element);

            while(xPNI.MoveNext())
            {
                string file = xPNI.Current.GetAttribute("AssemblyFile", string.Empty);
                FileInfo fileInfo = new FileInfo(file);
                if (fileInfo.Exists)
                {
                    pModules.Add(fileInfo);
                }
            }
        }

        #endregion

    }
}